Thumb

JavaScript Const

1/22/2020 1:51:25 AM

Constant look like a ‘var’ or ‘let’ variables but when const value once assign this value never be change. Const only have an option to help with to efficiency how your program run and manages your memory on the computer because you have some data or you have a variable in your program but you know its value never going to be change. The computer can be smart how to know the value never be change. When we use the const then computer know this is constant so the value never changes. This const keyword we use function or object not only variables. Now given bellow the constant example code and explain the code:

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<script type="text/javascript">
// Use let keyword
let a=50;
console.log("With out again assine show the a value :" +a);
a=100;
console.log("Again assine show the a value :" +a);

// Use const keyword
const b=50;
console.log("With out again assine show the b value :" +b);
//This assgin is invelid!
b=100;
console.log("Again assine show the b value :" +b);
</script>
</body>
</html>

We can see the ‘let’ variable to reassign the value and also print the value but constant variables first assign value then prints but when we re assign the value into the constant variable it can’t assign it’s invalid. So constant variable value we can’t reassign the value.